package com.zisu.springbootsource.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author: 蔡翔
 * @Date: 2020/5/5 20:39
 * @Version 1.0
 */
@Component
public class TestService implements ApplicationContextAware {

    //获取 应用的上下文
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public String test(){
        // 返回上下文环境变量中  键为key1 的值
        return applicationContext.getEnvironment().getProperty("key2");
    }
}
